<?php
/**
 * kol订单
 * (model)
 */

namespace App\Models\KolManage;


use Illuminate\Database\Eloquent\Model;

class KolOrder extends Model{

    protected $table = 'k_kol_order';

    protected $guarded = [];

    /**
     * 合作进度
     */
    const PROGRESS_1  = 1; //待寄样
    const PROGRESS_2  = 2; //运输中
    const PROGRESS_3  = 3; //已接收（测评中）
    const PROGRESS_4  = 4; //推广中
    public static $_cooperate_progress = [
        self::PROGRESS_1 => '待寄样',
        self::PROGRESS_2 => '运输中',
        self::PROGRESS_3 => '已接收',
        self::PROGRESS_4 => '推广中',
    ];

    /**
     * 合作状态
     */
    const STATUS_1  = 1; //待上线
    const STATUS_2  = 2; //正常上线
    const STATUS_3  = 3; //已逾期
    const STATUS_4  = 4; //逾期上线
    public static $_cooperate_status = [
        self::STATUS_1 => '待上线',
        self::STATUS_2 => '正常上线',
        self::STATUS_3 => '已逾期',
        self::STATUS_4 => '逾期上线',
    ];

    public function detail(){
        return $this->hasMany(KolOrderDetail::class, 'order_no', 'order_no');
    }

    public function kol(){
        return $this->belongsTo(Kol::class, 'kol_code', 'kol_code');
    }

    public static function getDownloadData($res)
    {
        foreach ($res as $model){
            $temp = [
                $model->order_no ?? '',
                Kol::getValueById($model->kol_id, 'media_account') ?? '',
                $model->remark ?? '',
            ];
            yield $temp;
        }
    }

}
